const {
    Mysql,
    TripleDecrypt
} = require('../tools');
module.exports = async ctx => {
    let {
        payInfo: requestBody
    } = ctx.request.body;
    try {
        let result = JSON.parse(TripleDecrypt(requestBody));
        let {
            vid,
            orderId,
            openId,
            payAmount,
            uid,
            payInfo
        } = result;
        let sql = `INSERT INTO orderList(uid,type,vid,orderId,openId,money,payInfo) VALUES(${uid},'MOVIE',${Number(vid)},'${orderId}','${openId}',${Number(payAmount)},'${payInfo}')`;
        let res = await Mysql(sql);
        if (res.affectedRows == 1) {
            let sql2 = `INSERT INTO buyVideo(uid,openId, vid, orderId, money) VALUES (${Number(uid)},'${openId}', ${Number(vid)}, '${orderId}', ${Number(payAmount)})`;
            await Mysql(sql2);
            ctx.state.data = {
                code: '001',
                data: 'ok'
            }
        } else {
            ctx.state.data = {
                code: '002',
                msg: '内部错误'
            }
        }
    } catch (error) {
        ctx.state.data = {
            code: '002',
            msg: '内部错误'
        }
    }
}